<?php

class Links_header_model extends CI_Model {

    public function get() {
        return $this->_generate();
    }

    private function _generate() {
        $module = $this->uri->segment(1);
        $action = $this->uri->segment(2);
        $toReturn = array();

        array_push($toReturn, '<a href="' . site_url() . '">Accueil du site</a>');

        switch ($module) {
            case 'account':
                switch ($action) {
                    case 'login':
                        array_push($toReturn, '<a href="' . site_url('account/login') . '">Identification</a>');
                        break;

                    default:
                        break;
                }
                break;

            case 'corporates':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('corporates/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('corporates/admin') . '">Sociétés</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('corporates/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_CORPORATE_GET_NAME"(' . $id . ') AS "CRP_NAME"')->result();
                                $corporate = $tmp[0]->CRP_NAME;

                                array_push($toReturn, '<a href="' . site_url('corporates/admin/edit/' . $id) . '">Edition de la société "' . $corporate . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    case 'adminCustomers':
                        $id = $this->uri->segment(3);
                        $this->db = $this->load->database('DB_PLASTPROD', true);
                        $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_CORPORATE_GET_NAME"(' . $id . ') AS "CRP_NAME"')->result();
                        $corporate = $tmp[0]->CRP_NAME;

                        array_push($toReturn, '<a href="' . site_url('corporates/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('corporates/admin') . '">Sociétés</a>');
                        array_push($toReturn, '<a href="' . site_url('corporates/adminCustomers/' . $id) . '">Salariés de "' . $corporate . '"</a>');


                        switch ($this->uri->segment(4)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('corporates/adminCustomers/' . $id . '/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $idCus = $this->uri->segment(5);

                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_CUSTOMER_GET_FIRST_NAME"(' . $idCus . ') AS "FIRST_NAME"')->result();
                                $firstName = $tmp[0]->FIRST_NAME;

                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_CUSTOMER_GET_LAST_NAME"(' . $idCus . ') AS "LAST_NAME"')->result();
                                $lastName = $tmp[0]->LAST_NAME;

                                array_push($toReturn, '<a href="' . site_url('corporates/adminCustomers/' . $id . '/edit/' . $idCus) . '">Edition du salarié "' . $lastName . ' ' . $firstName . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;

            case 'employees':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('employees/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('employees/admin') . '">Employés</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('employees/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);

                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_EMPLOYEE_GET_FIRST_NAME"(' . $id . ') AS "FIRST_NAME"')->result();
                                $firstName = $tmp[0]->FIRST_NAME;

                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_EMPLOYEE_GET_LAST_NAME"(' . $id . ') AS "LAST_NAME"')->result();
                                $lastName = $tmp[0]->LAST_NAME;

                                array_push($toReturn, '<a href="' . site_url('employees/admin/edit/' . $id) . '">Edition de l\'employé "' . $lastName . ' ' . $firstName . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;

            case 'groups':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('groups/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('groups/admin') . '">Groupes</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('groups/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_INTRANET"."F_GROUP_GET_NAME"(' . $id . ') AS "GRP_NAME"')->result();
                                $group = $tmp[0]->GRP_NAME;

                                array_push($toReturn, '<a href="' . site_url('groups/admin/edit/' . $id) . '">Edition du groupe "' . $group . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;

            case 'menus':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('menus/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('menus/admin') . '">Menus</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('menus/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_INTRANET"."F_MENU_GET_NAME"(' . $id . ') AS "MNU_NAME"')->result();
                                $menu = $tmp[0]->MNU_NAME;

                                array_push($toReturn, '<a href="' . site_url('menus/admin/edit/' . $id) . '">Edition du menu "' . $menu . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    case 'adminLinks':
                        array_push($toReturn, '<a href="' . site_url('menus/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('menus/admin') . '">Menus</a>');

                        $id = $this->uri->segment(3);
                        $this->db = $this->load->database('DB_PLASTPROD', true);
                        $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_INTRANET"."F_MENU_GET_NAME"(' . $id . ') AS "MNU_NAME"')->result();
                        $menu = $tmp[0]->MNU_NAME;

                        array_push($toReturn, '<a href="' . site_url('menus/adminLinks/' . $id) . '">Liens du menu "' . $menu . '"</a>');

                        switch ($this->uri->segment(4)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('menus/adminLinks/' . $id . '/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $idLink = $this->uri->segment(5);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_INTRANET"."F_LINK_GET_NAME"(' . $idLink . ') AS "LNK_NAME"')->result();
                                $link = $tmp[0]->LNK_NAME;

                                array_push($toReturn, '<a href="' . site_url('menus/adminLinks/' . $id . '/edit/' . $idLink) . '">Edition du lien "' . $link . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;

            case 'products':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('products/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('products/admin') . '">Produits</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('products/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_PRODUCTION"."F_PRODUCT_TYPE_GET_NAME"(' . $id . ') AS "PDT_NAME"')->result();
                                $product = $tmp[0]->PDT_NAME;

                                array_push($toReturn, '<a href="' . site_url('products/admin/edit/' . $id) . '">Edition du produit "' . $product . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;


            case 'services':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('services/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('services/admin') . '">Services</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('services/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_SERVICE_GET_NAME"(' . $id . ') AS "SRV_NAME"')->result();
                                $service = $tmp[0]->SRV_NAME;

                                array_push($toReturn, '<a href="' . site_url('services/admin/edit/' . $id) . '">Edition du service "' . $service . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;

            case 'users':
                switch ($action) {
                    case 'admin':
                        array_push($toReturn, '<a href="' . site_url('users/admin') . '">Administration</a>');
                        array_push($toReturn, '<a href="' . site_url('users/admin') . '">Utilisateurs</a>');

                        switch ($this->uri->segment(3)) {
                            case 'add':
                                array_push($toReturn, '<a href="' . site_url('users/admin/add') . '">Ajouter</a>');
                                break;

                            case 'edit':
                                $id = $this->uri->segment(4);
                                $this->db = $this->load->database('DB_PLASTPROD', true);
                                $tmp = $this->db->query('SELECT "DB_PLASTPROD"."S_BUSINESS_DATA"."F_USER_GET_LOGIN"(' . $id . ') AS "USR_LOGIN"')->result();
                                $login = $tmp[0]->USR_LOGIN;

                                array_push($toReturn, '<a href="' . site_url('users/admin/edit/' . $id) . '">Edition de "' . $login . '"</a>');
                                break;

                            default:
                                break;
                        }

                        break;

                    default:
                        break;
                }
                break;

            default:
                break;
        }

        return implode(' > ', $toReturn);
    }

}